class SessionsController < ApplicationController
  layout "login"
  
  skip_before_filter :check_user_logged, 
                     :redirect_if_not_active,
                     :set_time_zone
  
  def new
    puts flash[:notice]
    if user_logged?
      redirect_to root_url and return
    else
      reset_session
    end
  end
  
  def create
    user = authenticate(params[:logon], params[:password])
     
    if user
      session[:user_id] = user.id
      if session[:return_to]
        redirect_to session[:return_to] and return
      else 
        redirect_to root_url and return
      end
    else
      flash.now[:notice] = I18n.t :login_fail, :scope => [:authentication, :messages, :error]
      render :action => "new"
    end
  end
  
  def destroy
    reset_session
    redirect_to login_url
  end
end